



var theData = new Vue({
    el: "#wrap",
    data: {
        nowPage: 1,   //当前页码
        totalPage: 0,  //总页码
        paginationItems: [   //页面数组
            /*{page:{}}*/  //数据格式
        ],
        tableItems: [       //表格数组
            /*{info:{}}*/  //数据格式
        ],
        flooritem:[

        ],
        setUp_user: {},     //配置的用户
        search_btn_remark: "",    //存放用户搜索内容
        token: token,        //input file 的加密
        time: unixtime       //input file 的加密
    },
    methods: {
        getList: function (nextPage) {   //获取每个分页的数据
            var that = this;
            var search = "";
            if (that.search_btn_remark != "") {
                search = that.search_btn_remark;
            }
            $.ajax({
                url: 'api/out/get_out_list.php',
                type: 'POST',
                async:false,
                data: {
                    token: token,
                    time: unixtime,
                    nextPage: nextPage,
                    search: search
                },
                dataType: 'JSON',
                beforeSend: function () {
                    $("#loading-mask").show();
                },
                error: function () {
                    $("#loading-mask").hide();
                    MyAlert("请求超时");
                },
                success: function (res) {
                    $("#loading-mask").hide();
                    if (res.err == 0) {
                        that.tableItems = res.msg;
                        console.log(that.tableItems);
                        that.nowPage = nextPage;
                    } else {
                        MyAlert(res.msg);
                    }
                }
            })
        },
        getPagination: function () {    //获取分页数量
            var that = this;
            var search = "";
            if (that.search_btn_remark != "") {
                search = that.search_btn_remark;
            }
            $.ajax({
                url: 'api/out/out_pag_info.php',
                type: 'POST',
                async:false,
                data: {
                    token: token,
                    time: unixtime,
                    search: search
                },
                dataType: 'JSON',
                beforeSend: function () {
                    $("#loading-mask").show();
                },
                error: function () {
                    $("#loading-mask").hide();
                    MyAlert("分页请求超时");
                },
                success: function (res) {
                    $("#loading-mask").hide();
                    if (res.err == 0) {
                        console.log(res.msg);
                        that.paginationItems = res.msg;
                        that.totalPage = res.total_page;
                    } else {
                        MyAlert(res.msg);
                    }
                }
            })
        },
        search: function () {      //查询
            var regSpace = /^\s+$/;
            if ($("#search-text").val() && !regSpace.test($("#search-text").val())) {
                this.search_btn_remark = $("#search-text").val();
                this.getPagination();
                this.getList(1);
            } else {
                MyAlert("请输入搜索内容");
            }
        },

        getfloor:function(){//获取楼宇信息
            var that = this;
            $.ajax({
                url: 'api/room/get_floor.php',
                type: 'POST',
                async:false,
                data: {
                    token: token,
                    time: unixtime,
                },
                dataType: 'JSON',
                beforeSend: function () {
                    $("#loading-mask").show();
                },
                error: function () {
                    $("#loading-mask").hide();
                    MyAlert("分页请求超时");
                },
                success: function (res) {
                    $("#loading-mask").hide();
                    if (res.err == 0) {
                        that.flooritem = res.msg;
                        console.log(that.flooritem);
                    } else {
                        MyAlert(res.msg);
                    }
                }
            })
        },

        changefloor:function () {
            var that = this;
            console.log(that.flooritem);
            console.log(that.tableItems);
            for(var i=0;i<that.tableItems.length;i++){//对比选择的楼宇ID获取楼宇名称
                for(var j =0;j<that.flooritem.length;j++)
                    if(that.tableItems[i].info.stay_floor_id===that.flooritem[j].info.floor_id){
                        that.tableItems[i].info.stay_floor_id= that.flooritem[j].info.floor_name;
                    }
            }

        }


    }
});

theData.getfloor();//首次加载获取楼宇信息
theData.getPagination();   //首次加载总页码
theData.getList(theData.nowPage);  //首次加载首个分页
theData.changefloor();